<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" scroll="no">
<%@ taglib prefix="ef" uri="control"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${Title}</title>
<link rel="shortcut icon" href="${res}favicon.ico" type="image/x-icon" />
 <!--Basic Styles-->
<link href="../framework/css/font.css" rel="stylesheet" />
<link href="../framework/miniui/themes/material/miniui.css" rel="stylesheet" />
<link href="../framework/css/app.min.1.css" rel="stylesheet" type="text/css" />
<link href="../framework/css/app.min.2.css" rel="stylesheet" type="text/css" />
<script src="../framework/main.js" type="text/javascript"></script>
<style type="text/css">
    html, body{
        margin:0;padding:0;border:0;width:100%;height:100%;overflow:hidden;
    }    
    </style>
</head>
<ef:init method="MemberRole.init">
<body class="body-detail">
<script>
function addMemberToRole(){
	if(!$V('RoleID')||$V('RoleID')=="null"){
		top.mini.alert("@{Common.PleaseSelectRowFirst}!");
		return;
	}
	mini.open({
		width : 800,
		height : 390,
		title : "用户列表",
		url : "${ctx}mhr/roleUserListDialog.jhtml?RoleID="+$V('RoleID'),
		onOk : addMemberToRoleSave
	});
}

function addMemberToRoleSave(){
	var arr = $DW.mini.get('dg1').getSelectedValue();
	if(!arr||arr.length==0){
		top.mini.alert("@{Common.PleaseSelectRowFirst}!");
		return;
	}
	var dc = {RoleID:$V('RoleID'),MemberIDs:arr.join()};
	Server.sendRequest("MemberRole.addMemberToRole",dc,function(response){
		if(response.Status == 1) {
			top.mini.showTips({content:response.Message,state:'success'});
			$D.close();
			mini.get('dg1').reload();
		} else {
			top.mini.alert(response.Message,null,response.Status);
		}
	});
}

function delMemberFromRole(){
	var arr = mini.get('dg1').getSelectedValue();
	if(!arr||arr.length==0){
		top.mini.alert("@{Common.PleaseSelectRowFirst}!");
		return;
	}
	top.mini.confirm("@{Common.ConfirmDelete}",function(action){
		var dc = {RoleID:$('#RoleID').val(),MemberIDs:arr.join()};
		if(action == "ok"){
			Server.sendRequest("MemberRole.delMemberFromRole",dc,function(response){
				if(response.Status == 1) {
					top.mini.showTips({content:response.Message,state:'success'});
					mini.get('dg1').clearSelect();
					mini.get('dg1').reload();
				} else {
					mini.get(response.Message,null,response.Status);
				}
			});	
		}
	});
}
Page.onLoad(function(){
	if(!$V("RoleID")){
		mini.get('dg1').disable();
		mini.get('addBtn').disable();
		mini.get('removeBtn').disable();
	} else {
		mini.get('dg1').load({RoleID:$V(RoleID)});	
	}
});
</script>
<input class="mini-hidden" id="RoleID" value="${ID}" />
<input class="mini-hidden" id="RoleName" value="${RoleName}" />
<div class="row" style="padding:10px;">
	<div class="col-xs-12">
		<div class="card z-depth-1" style="margin-bottom:0;">
              <div class="card-body">
                <table class="table">
					<tbody>
						<tr><td width="30%" align="right">角色名：</td><td>${RoleName}</td></tr>
						<tr><td align="right">所属机构：</td><td>${BranchName}</td></tr>
						<tr><td align="right">备注：</td><td>${Memo}</td></tr>
					</tbody>
				</table>
	        </div>
	    </div>
	</div>
</div>
<div class="mini-toolbar" style="margin:2px 10px;" id="toolbar1" plain="true">
     <a id="addBtn" class="mini-button" iconCls="icon-active-user" onClick="addMemberToRole()" plain="true">添加用户到角色</a>
     <a id="removeBtn" class="mini-button" iconCls="icon-remove" onClick="delMemberFromRole()" plain="true">从角色中删除用户</a>
</div>
<div class="mini-fit" style="padding:0 10px 10px 10px;">
	<div id="dg1" class="mini-datagrid z-depth-1" style="width:100%;height:100%;" method="MemberRole.bindGrid"  idField="Member" multiSelect="true">
	    <div property="columns">
	       	<div type="indexcolumn"></div>
	        <div type="checkcolumn" ></div>        
	         <div field="EmployeeNumber" width="10%">员工编号</div>
            <div field="UserName" width="13%">用户名</div>
            <div field="RealName" width="12%">真实姓名</div>
            <div field="RoleNames" width="40%">所属角色</div>
	    </div>
	</div>
</div>
</body>
</ef:init>
</html>